package sum.SumProvinceMarriages;

import org.apache.hadoop.io.FloatWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;


public class SumProMarriagesMapper extends Mapper<LongWritable, Text, SumProMarriagesBean, FloatWritable> {
    //int i = 0;
    SumProMarriagesBean outKey = new SumProMarriagesBean();
    FloatWritable outValue = new FloatWritable();


    @Override
    protected void map(LongWritable key, Text value,Context context) throws IOException, InterruptedException {
        //i++;
        if (key.get() == 0){
            return;
        }

        String[] fields = value.toString().split(",");
        /**
         * 北京市,东城区,2022年,0.53(结婚登记数),0.52,0.62,0.47,0.01(涉外结婚登记),0.25(离婚登记数),148,
         */
        String year = fields[2];
        String province = fields[0];
        outKey.set(year,province);
        //System.out.println("1:"+i+"2:"+value.toString());
        float marriage = Float.parseFloat(fields[3]);

        outValue.set(marriage);

        context.write(outKey,outValue);
    }
}
